#!/usr/bin/env node

import { Command } from 'commander';
import { logger } from './utils/logger';
import { CLIError } from './types';

import { authCommands } from './commands/auth';
import { projectCommands } from './commands/project';
import { envCommands } from './commands/env';
import { moduleCommands } from './commands/module';
import { secretCommands } from './commands/secret';
import { debugCommands } from './commands/debug';
import { devCommands } from './commands/dev';
import { publishCommands } from './commands/publish';
import { collaborationCommands } from './commands/collaboration';
import { configCommands } from './commands/config';

const program = new Command();

program
  .name('cm')
  .description('CModel CLI - A comprehensive tool for cloud module management')
  .version('1.0.0');

authCommands(program);
projectCommands(program);
envCommands(program);
moduleCommands(program);
secretCommands(program);
debugCommands(program);
devCommands(program);
publishCommands(program);
collaborationCommands(program);
configCommands(program);

program.parseAsync(process.argv).catch((error) => {
  if (error instanceof CLIError) {
    logger.error(error.message);
    process.exit(1);
  } else {
    logger.error('An unexpected error occurred:');
    logger.error(error.message);
    if (process.env.DEBUG) {
      console.error(error.stack);
    }
    process.exit(1);
  }
});